// pages/member/memberCenter.js
import getIn from '../../sdk/utils/getIn';
import {
    ORDER_TYPE_UNPAID, // 未付款
    ORDER_TYPE_PAID, // 已付款
    ORDER_TYPE_COMPLETED, // 已完成
    ORDER_TYPE_CANCELED, // 已取消
    ORDER_TYPE_CLOSED, // 已关闭
    TARIFF_DESCRIPTION_ID,
} from '../../utils/config';
import {LOGIN_VIEW, EXIT_PHONE, ORDER_LIST, ARTICLE_DETAIL} from '../../utils/url';
import { addNotifier, removeNotifier } from '../../sdk/utils/NotifyRegistryCenter.js';

Page({

  /**
   * 页面的初始数据
   */
  data: {
      ORDER_TYPE_UNPAID,
      ORDER_TYPE_PAID,
      ORDER_TYPE_COMPLETED,
      ORDER_TYPE_CANCELED,
      ORDER_TYPE_CLOSED,
      userInfo: undefined,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getStorage();
    addNotifier && addNotifier('LOGIN_NOTI', () => {
        this.getStorage();
    }, this);
  },
    getStorage() {
        const userInfo = wx.getStorageSync('userInfo');
        this.setData({ userInfo });
    },
    // 跳转授权登陆页面
    toLogin() {
      const { userInfo:{ phone } } = this.data;
      if(!phone) {
          global.navigateHelper.navigateTo({ pathname: EXIT_PHONE });
      } else {
          global.navigateHelper.navigateTo({ pathname: LOGIN_VIEW });
      }
    },
    // 跳转手机绑定页面
    toPhone() {
      const queryString = 'exdit=1'
      global.navigateHelper.navigateTo({ pathname: EXIT_PHONE, queryString });
    },
    // 跳转订单列表页
    toOrder(e) {
        const status = getIn(e.currentTarget.dataset, ['status']);
        const queryString = status || status == 0 ? `status=${status}` : '';
        global.navigateHelper.navigateTo({ pathname: ORDER_LIST, queryString });
    },
    toExpiain() {
        const queryString = `id=${TARIFF_DESCRIPTION_ID}&cate_name=资费说明`;
        global.navigateHelper.navigateTo({ pathname: ARTICLE_DETAIL, queryString });
    },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
      removeNotifier && removeNotifier('LOGIN_NOTI', this);
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})